/*
 * Copyright (c) 2011 Martin Farrell (farrelmr@gmail.com)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef ROUTEVIEWERGUI_H
#define ROUTEVIEWERGUI_H

#include <QtGui/QWidget>
#include <QDialog>
#include <QString>
#include <QTimer>
#include <QLCDNumber>

#include <QNetworkAccessManager>
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkReply>

#include <QDesktopServices>

#include "ui_routeviewergui.h"
#include "ANTlocalController.h"
#include "ant.h"

#define REFRESHRATE        1000 // screen refresh in milliseconds

#define ROUTEVIEWER_HTTP_STATUS_INIT               0
#define ROUTEVIEWER_HTTP_STATUS_NO_BROWSER_RUNNING 1
#define ROUTEVIEWER_HTTP_STATUS_RUNNING            2

// Status settings
#define RT_MODE_ERGO    0x0001        // load generation modes
#define RT_MODE_SPIN    0x0002        // spinscan like modes
#define RT_RUNNING      0x0100        // is running now
#define RT_PAUSED       0x0200        // is paused
#define RT_RECORDING    0x0400        // is recording to disk
#define RT_WORKOUT      0x0800        // is running a workout
#define RT_STREAMING    0x1000        // is streaming to a remote peer

class routeviewerGUI : public QWidget
{
    Q_OBJECT

public:
    routeviewerGUI(QWidget *parent = 0);
    ~routeviewerGUI();
    
    ANT *myANTlocal;
    ANTlocalController *myANTlocalController;
    
    DeviceConfiguration deviceConfiguration;
    
    RealtimeData rtData;
    
    QTimer *gui_timer;
    
    int displayUnits; // 0 - kmph / 1 - mph
    
    int ROUTEVIEWER_HTTP_STATUS;
    
    int status;
    
    double speedVal;
    
    QString pairingId;
    
    QString pairingUrl;
    
    int lastRealTimeRecord;
    
    QNetworkAccessManager* qNetworkAccessManager;

    Ui::routeviewer ui;
    
private slots:
    void on_changeUnits_clicked();
    void on_startrv_clicked();
    void on_stoprv_clicked();
    void guiUpdate_ontimer();
    void finishedSlot(QNetworkReply* reply);

};

#endif // ROUTEVIEWERGUI_H
